package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.wxsearch.WxSearchIndexData;
import com.cskaoyan.service.WxSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: yudefu
 * @date 2021年06月07日  23:30
 * @description: 搜索模块
 */

@RestController
@RequestMapping("wx/search")
public class WxSearchController {

    @Autowired
    WxSearchService wxSearchService;

    @RequestMapping("index")
    public BaseRespVo getSearchIndex() {

        WxSearchIndexData wxSearchIndexData = wxSearchService.getSearchIndex();

        return BaseRespVo.ok(wxSearchIndexData);
    }

    @RequestMapping("helper")
    public BaseRespVo searchHelper(String keyword) {

        List<String> keywords = wxSearchService.searchHelper(keyword);

        return BaseRespVo.ok(keywords);
    }

    @RequestMapping("clearhistory")
    public BaseRespVo clearSearchHistory() {

        int res = wxSearchService.clearSearchHistory();

        if (res > 0) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail();

    }
}
